<template>
  <div>
    <j-modal
    :title="title"
    :width="width"
    :confirmLoading="confirmLoading"
    :visible="visible"
    switchFullscreen
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
      <a-table ref="table" size="middle" :pagination="ipagination" :scroll="{ x: true }" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :loading="loading" class="j-table-force-nowrap"  @change="handleTableChange">
      </a-table>
      <template slot="footer">
        <a-button @click="handleCancel">关闭</a-button>
      </template>
    </j-modal>
  </div>
</template>

<script>
  import moment from "moment"
  import { httpAction,getAction } from '@/api/manage'
  export default {
    name: 'AssetCheckModal',
    components: {
    },
    props: {
    },
    data () {
      return {
        dataSource:[],
        loading:false,
        // 表头
        columns: [
          {
            title: '资产编码',
            align: "center",
            dataIndex: 'assetCoding'
          },
          {
            title: '资产名称',
            align: "center",
            dataIndex: 'assetName'
          },
          {
            title: '所属人',
            align: "center",
            dataIndex: 'owner'
          },
          {
            title: '使用人',
            align: "center",
            dataIndex: 'userer'
          },
          {
            title: '日期',
            align: "center",
            dataIndex: 'useTime'
          },
          {
            title: '状态',
            align: "center",
            dataIndex: 'status',
            customRender: function (text) {
              if (text === '1') {
                return '进行中'
              } else if (text === '2') {
                return '已结束'
              } else {
                return text
              }
            }
          },
          {
            title: '盘点状态',
            align: "center",
            dataIndex: 'randomStatus',
            customRender: function (text) {
              if (text === '1') {
                return '正常'
              } else if (text === '2') {
                return '异常'
              } else {
                return text
              }
            }
          },{
            title: '异常原因',
            align: "center",
            dataIndex: 'msgDesc'
          }
        ],
        visible: false,
        confirmLoading: false,
        disableSubmit:false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        title:'',
        width:1000,
        visible: false,
        disableSubmit: false,
        confirmLoading: false,
        
        url: {
          list: "/assets/assetsItem/list",
          queryListByDepartId: "/assets/assetsRandomStockItem/list",
        },
        ipagination: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + "-" + range[1] + " 共" + total + "条"
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
      }
    },
    computed: {
      formDisabled() {
        return this.disabled
      },
      validatorRules(){}
    },
    created() {
     //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      moment,
      // 新增
      add () {
        this.edit(this.modelDefault);
      },
      // 编辑、详情
      edit(record,tag) {
        if(tag!=1){
          this.ipagination.current = 1
        }
        this.model = Object.assign({}, record);
        this.visible=true
        this.dataList(this.model)
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleCancel () {
        this.close()
      },
      dataList(model){
        const that = this
        let formData = {
          applyId: model.id,
          pageNo:this.ipagination.current,
          pageSize:this.ipagination.pageSize
        }
        getAction(this.url.queryListByDepartId,formData).then((res) => {
          if(res.success){
            this.dataSource = res.result.records
            this.ipagination.total = res.result.total;
          }
        }).finally(() => {
          that.confirmLoading = false;
        })
      },
      handleTableChange(pagination, filters, sorter) {
        this.ipagination = pagination;
        this.edit(this.model,1);
      }
    }
  }
</script>
<style scoped>
  .toolBt{
    display: flex;
    align-content: center;
  }
</style>